package me.leiusual.sharing.ui.mine.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import me.leiusual.sharing.R
import me.leiusual.sharing.api.model.Invited

/**
 * Create by leiusual on 2018/7/22
 */
class MineInvitedAdapter(
    private val clickListener: (Invited.Response.User) -> Unit,
    private val renewClickListener: (Invited.Response.User) -> Unit
) : PagedListAdapter<Invited.Response.User, MineInvitedViewHolder>(DIFF_CALLBACK) {

  companion object {
    private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Invited.Response.User>() {

      override fun areItemsTheSame(oldItem: Invited.Response.User, newItem: Invited.Response.User): Boolean {
        return oldItem.id == newItem.id
      }

      override fun areContentsTheSame(oldItem: Invited.Response.User, newItem: Invited.Response.User): Boolean {
        return oldItem == newItem
      }
    }
  }

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MineInvitedViewHolder {
    val inflater = LayoutInflater.from(parent.context)
    val itemView = inflater.inflate(R.layout.view_holder_mine_invited, parent, false)
    return MineInvitedViewHolder(itemView, clickListener, renewClickListener)
  }

  override fun onBindViewHolder(holderParent: MineInvitedViewHolder, position: Int) {
    holderParent.bind(getItem(position) ?: return)
  }
}